﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACS.Data;
using System.Data;
using WoSoft.PACS.Data.Models;

namespace WoSoft.PACS.Data.Doctor
{
    /// <summary>
    /// 医生数据处理
    /// </summary>
    public class DoctorData : Db
    {

        //获取医护人员 ID信息
        public DoctorModel GetModelByID(string ID)
        {
            var sql = "select * from 医护人员 where ID = @id";
            var dyobj = this.SqlDatabase.Sql(sql, null)
                .Parameter("id", ID)
                .QuerySingle<dynamic>();
            if (dyobj != null)
            {
                return new DoctorModel()
                {
                    ID = dyobj.ID,
                    DepartmentID = dyobj.部门ID,
                    Name = dyobj.姓名,
                    Code = dyobj.简码,
                    Sex = dyobj.性别,
                    Education = dyobj.学历,
                    Nation = dyobj.民族,
                    Birthday = dyobj.出生日期,
                    Tel = dyobj.电话,
                    Email = dyobj.邮箱,
                    Level = dyobj.职级,
                    NameCode = dyobj.编码
                };
            }

            return null;
        }

        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Models.DoctorModel model)
        {
            if (model.Birthday == DateTime.MinValue)
            {
                model.Birthday = DateTime.MaxValue;
            }

            return this.SqlDatabase.Insert("医护人员")
                .Column("ID", model.ID)
                .Column("部门ID",model.DepartmentID)
                .Column("姓名",model.Name)
                .Column("简码",model.Code)
                .Column("性别",model.Sex)
                .Column("民族",model.Nation)
                .Column("学历",model.Education)
                .Column("出生日期",model.Birthday)
                .Column("电话",model.Tel)
                .Column("邮箱",model.Email)
                .Column("职级",model.Level)
                .Column("编码",model.NameCode)
                .Execute(); 
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Models.DoctorModel model)
        {
            return this.SqlDatabase.Update("医护人员")
                .Column("部门ID", model.DepartmentID)
                .Column("姓名", model.Name)
                .Column("简码", model.Code)
                .Column("性别", model.Sex)
                .Column("民族", model.Nation)
                .Column("学历", model.Education)
                .Column("出生日期", model.Birthday)
                .Column("电话", model.Tel)
                .Column("邮箱", model.Email)
                .Column("职级", model.Level)
                .Column("编码", model.NameCode)
                .Where("ID", model.ID)
                .Execute();
        }

        //删除医护人员
        public void Delete(string _ID)
        {
            this.SqlDatabase.Delete("医护人员")
                .Where("ID", _ID)
                .Execute();
        }


    }
}
